import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter);

// --------------解决路由两次点击报错----------------------------
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};

// --------------懒加载配置-----------------------
const Home = () => import('views/home/Home.vue');
// const Category = () => import('views/category/Category');
// const Cart = () => import('views/cart/Cart');
// const Profile = () => import('views/profile/Profile');
// const Detail = () => import('views/detail/Detail');


// 编写路由
const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path: '/category',
    name: 'Category',
    component: Home
  },
  {
    path: '/cart',
    name: 'Cart',
    component: Home
  },
  {
    path: '/profile',
    name: 'Profile',
    component: Home
  },
  {
    path: '/detail',
    name: 'Detail',
    component: Home
  }
];

// 创建router路由对象
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});


// 导出
export default router
